package com.ruoyi.test.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.test.domain.PcjAble;
import com.ruoyi.test.service.IPcjAbleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * 擅长配置Controller
 *
 * @author ms
 * @date 2024-03-11
 */
@RestController
@RequestMapping("/pcj/able")
public class PcjAbleController extends BaseController {
    @Autowired
    private IPcjAbleService pcjAbleService;

    /**
     * 分页查询擅长配置列表
     *
     * @param params 最基本参数{"pageNum":1,"pageSize":10}，其他参数自行定义
     */
    @PreAuthorize("@ss.hasPermi('pcj:able:list')")
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam Map<String, Object> params) {
        IPage<PcjAble> page = pcjAbleService.selectPcjAbleList(params);
        return getDataTableMp(page);
    }


    /**
     * 导出擅长配置列表
     */
    @PreAuthorize("@ss.hasPermi('pcj:able:export')")
    @Log(title = "擅长配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestBody Map<String, Object> params) {
        IPage<PcjAble> page = pcjAbleService.selectPcjAbleList(params);
        ExcelUtil<PcjAble> util = new ExcelUtil<PcjAble>(PcjAble.class);
        util.exportExcel(response, page.getRecords(), "擅长配置数据");
    }

    /**
     * 获取擅长配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('pcj:able:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(pcjAbleService.selectPcjAbleById(id));
    }

    /**
     * 新增擅长配置
     */
    @PreAuthorize("@ss.hasPermi('pcj:able:add')")
    @Log(title = "擅长配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PcjAble pcjAble) throws Exception {
        return toAjax(pcjAbleService.insertPcjAble(pcjAble));
    }

    /**
     * 修改擅长配置
     */
    @PreAuthorize("@ss.hasPermi('pcj:able:edit')")
    @Log(title = "擅长配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PcjAble pcjAble) throws Exception {
        return toAjax(pcjAbleService.updatePcjAble(pcjAble));
    }

    /**
     * 删除擅长配置
     */
    @PreAuthorize("@ss.hasPermi('pcj:able:remove')")
    @Log(title = "擅长配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(pcjAbleService.deletePcjAbleByIds(ids));
    }
}
